<template>
  <el-dialog title="新增校区" :visible.sync="dialogVisible" width="800px" :close-on-click-modal="false"
    :modal-append-to-body="false" v-drag2anywhere>
    <el-form :model="formData"  ref="formData" size="mini" label-width="80px" :rules="rules">
      <el-row>
        <el-col>
          <el-form-item label="校区名称" prop="title">
            <el-input v-model="formData.title" placeholder="校区名称"></el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="负责人">
            <el-input v-model="formData.manager" placeholder="负责人"></el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="联系电话">
            <el-input v-model="formData.mobile" placeholder="联系电话"></el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="机构地址">
            <el-input v-model="formData.address" placeholder="机构地址"></el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="小区简介">
            <el-input type="textarea" :rows="5" :maxlength="500" show-word-limit v-model="formData.desc"
              placeholder="小区简介"></el-input>
          </el-form-item>
        </el-col>

        <el-col style="text-align: center;">
          <el-button @click="handleCancel">取消</el-button>
          <el-button type="primary" @click="handleSave">保存</el-button>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        formData: {
          title: ''
        },
        rules:{
          "title":[{message:"请正确填写培训机构名称!",trigger:'blur',required:true}]
        }
      }
    },
    methods: {
      init() {
        this.formData = {
          title: '',
          desc: '',
          mobile: '',
          manager: '',
          address: ''
        }
      },
      handleCancel() {
        this.dialogVisible = false;
      },
      handleSave() {
         this.$refs.formData.validate(ok=>{

          const params = {
            title: this.formData.title,
            desc: this.formData.desc,
            mobile: this.formData.mobile,
            manager: this.formData.manager,
            address: this.formData.address
          }
          this.api_helper.post("api/institution/area/create", params).then(res => {
            if (res.status == 200 && res.data.code == 1) {
              this.$message.success({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
              this.dialogVisible = false;
              this.$emit("complete");
            } else {
              this.$message.error({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
            }
          })
        });

      }
    }
  }
</script>

<style>
</style>
